package com.lu.sys.controller;

import com.lu.common.annotation.SystemLog;
import com.lu.common.vo.CommonResult;
import com.lu.common.vo.PageResponse;
import com.lu.common.vo.Result;
import com.lu.sys.entity.Role;
import com.lu.sys.entity.vo.CourseDTO;
import com.lu.sys.entity.vo.CourseDelDTO;
import com.lu.sys.service.ICourseService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = {"课程接口列表"})
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private ICourseService courseService;

    @PostMapping("/addCourse")
    @SystemLog("新增课程")
    public Result<?> addCourse(@RequestBody CourseDTO courseDTO){//RequestBody可以把json数据转换为role对象

        courseService.addCourse(courseDTO);
        return Result.success("新增课程成功");
    }


    @GetMapping("/list")
    public  CommonResult<PageResponse<CourseDTO>> getCourseList(@RequestParam(value = "title",required = false) String title,
                                                                          @RequestParam(value = "pageNo") Long pageNo,
                                                                          @RequestParam(value = "pageSize") Long pageSize){
        return CommonResult.<PageResponse<CourseDTO>>builder()
                .data(courseService.getCourseList(title, pageNo, pageSize))
                .build();
    }

    @PostMapping("/updateCourse")
    @SystemLog("更新课程")
    public Result<?> updateCourse(@RequestBody CourseDTO courseDTO){
        courseService.updateCourse(courseDTO);
        return Result.success("修改课程成功");
    }

    @PostMapping("/del")
    @SystemLog("删除课程")
    public Result<?> deleteCourse(@RequestBody CourseDelDTO courseDelDTO){  //点击修改按钮后从数据库中查询信息的接口
        courseService.deleteCourse(courseDelDTO);
        return Result.success("删除角色成功");
    }

}
